package com.jay.lang.clazz;

import java.io.Console;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Map;
import java.util.Properties;

public class SystemCls {
	//-Djava.security.manager
	public static void main(String[] args) throws IOException {
		// in, out, err
		// BufferedReader buf = new BufferedReader(
		// new InputStreamReader(System.in));
		// String st = buf.readLine();
		//
		// st += ":processed";
		// System.out.println(st);
		// System.err.println(st);

		int[] src = { 1, 3, 5, 6, 7, 8 };
		int[] dest = new int[6];
		System.arraycopy(src, 0, dest, 0, 6);
		System.out.println(dest[2]);

		// No console in IDE
		Console console = System.console(); // 获得Console实例对象
		if (console != null) { // 判断是否有控制台的使用权
			String user = new String(console.readLine("Enter username:")); // 读取整行字符
			String pwd = new String(console.readPassword("Enter passowrd:")); // 读取密码,输入时不显示
			console.printf("Username is: " + user + "\n"); // 显示用户名
			console.printf("Password is: " + pwd + "\n"); // 显示密码
		} else {
			System.out.println("Console is unavailable."); // 提示无控制台使用权限
		}
		
		//time
		System.out.println(System.currentTimeMillis());
		System.out.println(System.nanoTime());
		
		// Security Manager
		SecurityManager sm = System.getSecurityManager();
		System.out.println(sm);
		
		System.out.println("-------Env--------");
		Map<String,String> envMap = System.getenv();
		for(String key : envMap.keySet())
		{
			System.out.println(key + ":" + envMap.get(key));
		}

		System.out.println("-------Props--------");
		Properties p = System.getProperties();
		for(String key : p.stringPropertyNames())
		{
			System.out.println(key + ":" + p.getProperty(key));
		}

		//返回默认的hashcode，不理重载
		System.out.println(System.identityHashCode(null));
		System.out.println(System.identityHashCode(new Test()));
		
		System.out.println(System.inheritedChannel());
		
		//JNI库
/*		System.load(filename);
		System.loadLibrary(libname);*/
		
		PrintStream out=System.out;//保存原输出流
		PrintStream ps=new PrintStream("./out.txt");
		System.setOut(ps);//设定新的输出流
		System.out.println("XXXXXXXXX");
		System.setOut(out);//恢复原有输出流
		System.out.println("back");

		System.exit(0);
	}
	
	static class Test{
		public int hashCode(){
			return 1;
		}
	}
}
